/*
 * remote.c
 *
 *  Created on: Oct 1, 2025
 *      Author: lianz
 */

#include "stm32f1xx_HAL.h"
#include "usart.h"

// 状态机
uint8_t forward = 0;	// 0x01
uint8_t back = 0;		// 0x03
uint8_t left = 0;		// 0x05
uint8_t right = 0;		// 0x07
uint8_t stop = 0;		// 0x09
// 串口存储
uint8_t rx_data;
uint8_t rx_buf[20];


// 接受指令并修改状态机
void Remote_Callback(void)
{
	switch (rx_data)
	{
		case 0x01:
			forward = 1;
			break;
		case 0x02:
			forward = 0;
			break;
		case 0x03:
			back = 1;
			break;
		case 0x04:
			back = 0;
			break;
		case 0x05:
			left = 1;
			break;
		case 0x06:
			left = 0;
			break;
		case 0x07:
			right = 1;
			break;
		case 0x08:
			right = 0;
			break;
		case 0x09:
			stop = 1;
			break;
		default:
			break;
	}
	if (stop == 1)
	{
		forward = 0, back = 0, left = 0, right = 0, stop = 0;
	}
	HAL_UART_Receive_IT(&huart3, &rx_data, 1);
}




